<template>
  <div class="app-content">
    <dk-table ref="DkTableRef" table-api="/gs_gold/admin.test" :cache-table="!getDev()">
      <template #questions_slot="{ row }">
        <el-button type="primary" size="small" @click="setQuestions(row)">
          <dk-icon icon="Edit" class="mr2"></dk-icon> {{ row.questions?.length || 0 }} 个
        </el-button>
      </template>
      <template #results_slot="{ row }">
        <el-button type="primary" size="small" @click="setQuestions(row)">
          <dk-icon icon="Edit" class="mr2"></dk-icon> {{ row.results?.length || 0 }} 个
        </el-button>
      </template>
      <template #cate_id_slot="{ row }">{{ row.category?.name }}</template>
    </dk-table>
    <dk-dialog v-model="showQuestion" title="编辑题目" width="1400px" :z-index="1000" :draggable="false">
      <DkTestQuestionContent
        v-if="showQuestion"
        :key="chooseItem.id"
        ref="question"
        :questions="chooseItem.questions"
        :results="chooseItem.results"
        :pid="chooseItem.id"
        @submit="onsubmit()"
      ></DkTestQuestionContent>
    </dk-dialog>
  </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { getDev } from '@/utils/auth'

defineOptions({
  name: 'TestList'
})
const DkTableRef = ref()
const chooseItem: any = ref([])
const showQuestion = ref(false)
const setQuestions = (item) => {
  chooseItem.value = item
  showQuestion.value = true
}

onMounted(() => {
  // DkTableRef.value.DkTable.getIndex()
  console.log(DkTableRef.value)
})

const onsubmit = () => {
  DkTableRef.value.DkTable.getIndex()
  showQuestion.value = false
}
</script>
<style></style>
